home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / tcoop10a.zip / DEMO.ZIP / TESTEFFE.CPP < prev    next >
C/C++ Source or Header  |  1991-11-20  |  2KB  |  127 lines

  1. //
  2. //    EFFECT.CPP
  3. //    version 1.00    11/20/91
  4. //    sound effects generator
  5. //    copyright (c) 1991 by James S. Clark
  6. //    all rights reserved
  7. //
  8.  
  9.  
  10. #include <dos.h>    // delay()
  11. #include <conio.h>    // getch()
  12. #include <stdlib.h>    // random()
  13.  
  14.  
  15. #include "effect.hpp"
  16.  
  17.  
  18. void    Effect::generator(int wave, int time, int f1, int f2,
  19.                 int step, int dur)
  20. {
  21.     int     currtime = 0;
  22.     int    f, dx = step;
  23.  
  24.     if (f1 < f2) { f = f1; f1 = f2; f2 = f1; }
  25.     f = f2;
  26.  
  27.     switch (wave) {
  28.     case SQUARE:
  29.         while (currtime < time) {
  30.             submit(f1, step);
  31.             submit(f2, dur);
  32.             currtime += step;
  33.             currtime += dur;
  34.         }
  35.         break;
  36.     case TRIANGLE:
  37.         while (currtime < time) {
  38.             submit(f, dur);
  39.             f += dx;
  40.             if (f > f1) dx = -dx;
  41.             if (f < f2) dx = -dx;
  42.             currtime += dur;
  43.         }
  44.         break;
  45.     case RAMPUP:
  46.         while (currtime < time) {
  47.             submit(f, dur);
  48.             f += step;
  49.             if (f > f1) f = f2;
  50.             currtime += dur;
  51.         }
  52.         break;
  53.     case RAMPDOWN:     {
  54.             f = f1;
  55.             while (currtime < time) {
  56.                 submit(f, dur);
  57.                 f -= step;
  58.                 if (f < f2) f = f1;
  59.                 currtime += dur;
  60.             }
  61.         }
  62.         break;
  63.     case RANDOM:
  64.         while (currtime < time) {
  65.             f = f2 + random(f1 - f2);
  66.             f1 -= step;
  67.             submit(f, dur);
  68.             currtime += dur;
  69.         }
  70.         break;
  71.     }
  72.     submit(0, 0);
  73. }
  74.  
  75.  
  76. // char    *effectnames[] = {
  77. //         "alarm", "bomb", "computer", "explode", "explode2",
  78. //         "laser", "phone", "police", "raygun", "tinkle"
  79. // }
  80.  
  81. main()
  82. {
  83.     Effect    fx;
  84.     int    i;
  85.  
  86.     fx.alarm(4000);
  87.     delay(5000);
  88.     fx.flush();
  89.  
  90.     fx.bomb(4000);
  91.     delay(5000);
  92.     fx.flush();
  93.  
  94.     fx.computer(4000);
  95.     delay(5000);
  96.     fx.flush();
  97.  
  98.     fx.explode(4000);
  99.     delay(5000);
  100.     fx.flush();
  101.  
  102.     fx.explode2(4000);
  103.     delay(5000);
  104.     fx.flush();
  105.  
  106.     fx.laser(4000);
  107.     delay(5000);
  108.     fx.flush();
  109.  
  110.     fx.phone(4000);
  111.     delay(5000);
  112.     fx.flush();
  113.  
  114.     fx.police(4000);
  115.     delay(5000);
  116.     fx.flush();
  117.  
  118.     fx.raygun(4000);
  119.     delay(5000);
  120.     fx.flush();
  121.  
  122.     fx.tinkle(4000);
  123.     delay(5000);
  124.     fx.flush();
  125. };
  126.  
  127.